package sctu.edu.java.year2016.team06.chenqiang.day20160606.chapter12_3;

import java.io.*;
import java.util.Scanner;

/**
 * Created by XQ on 2016/6/6.
 * 编写java程序，实现当用户输入姓名和密码时，将每一个姓名和密码存入文件。
 */
public class FileOutput {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入姓名：");
        String name = scan.next();
        System.out.println("请输入密码：");
        String password = scan.next();
        File newFile = new File("D:\\Test.txt");
        try {
            newFile.createNewFile();
            DataOutputStream dataOutputStream = new DataOutputStream(
                    new FileOutputStream(newFile)
            );
            dataOutputStream.write(name.getBytes());
            dataOutputStream.write(password.getBytes());
            dataOutputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
